package com.example.crmweb.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.crmweb.entity.Role;
import com.example.crmweb.service.impl.RoleServiceImpl;
import com.example.crmweb.lang.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  角色控制器
 * </p>
 *
 * @author -CRM-
 * @since 2022-03-18
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleServiceImpl roleService;

    /**
     * 查询所有角色
     * @return
     */
    @RequestMapping("/batchGet")
    public List<Role> findAll(){
        List<Role> roleList = roleService.list(Wrappers.query());
        return roleList;
    }


    /**
     * 添加角色
     * @param role
     * @return
     */
    @PostMapping("/create")
    public Result insert(Role role){
        return roleService.create(role);
    }

    /**
     * 更新角色
     * @param role
     * @return
     */
    @PutMapping("/move")
    public Result update(Role role){
        return roleService.modify(role);
    }

    /**
     * 删除角色
     * @param id
     * @return
     */
    @DeleteMapping("/cancel/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        return roleService.delete(id);
    }

}
